#!/usr/bin/pythonBasics
# -*- coding: utf-8 -*-
# @Time : 2021/4/12 10:50
# @Author : super
# @File : demo05
# @Project : pythonFile
'''查询「李」姓老师的数量'''

import mysql.connector.pooling

config = {
	'host':'localhost',
	'port':3306,
	'user':'root',
	'password':'root',
	'database':'test'
}

try:
	pool = mysql.connector.pooling.MySQLConnectionPool(
		**config,
		pool_size = 10
	)
	con = pool.get_connection()
	con.start_transaction()
	cursor = con.cursor()
	cursor.execute('select count(tname) from teacher where tname like "李%"')
	print(cursor.fetchall())
	lists = [
		('05','tom'),
		('06','jack')
	]
	cursor.executemany('INSERT INTO teacher(tid,tname) VALUES(%s,%s)',lists)
	if cursor.rowcount>0:
		print('新增成功!')
	cursor.execute('select * from teacher')
	print(cursor.fetchall())
	con.commit()
except Exception as e:
	if 'con' in dir():
		con.rollback()
	raise ValueError(e)